package com.cmpan.networkdisk.service;

import com.cmpan.networkdisk.dao.TypeMapper;
import com.cmpan.networkdisk.model.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * ClassName:TypeServiceImp
 * Package:com.cmpan.networkdisk.service
 * Description:
 *
 * @Date:2020/7/12 7:54
 * @com.chuangmei
 */
@Service
public class TypeServiceImp implements TypeService {

    @Resource
    private TypeMapper typeDao;

    @Override
    public List getAllType() {
        List<Type> allType = typeDao.selectAllType();
        return allType;
    }

    @Override
    public Type queryByPrimary(Long id) {
        Type type = typeDao.selectByPrimaryKey(id);
        return type;
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT ,propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public int updateByPrimary(Type type) {
        int count = typeDao.updateByPrimaryKey(type);
        return count;
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT ,propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public int deleteByPrimary(Long valueOf) {
        int count = typeDao.deleteByPrimaryKey(valueOf);
        return count;
    }

    @Override
    public int addType(Type type) {
        int count = typeDao.insertSelective(type);
        return count;
    }
}
